#!/bin/sh /etc/rc.common
# Copyright (C) 2013 OpenWrt.org

START=99
USE_PROCD=1

PROG=/usr/sbin/dialtool2
CONF=/tmp/dialtool2.conf

make_config()
{
        local apn auth_type user_name password proto mtu
        apn=`uci get modem.default.apn 2>/dev/null`
        auth_type=`uci get modem.default.auth_type 2>/dev/null`
        user_name=`uci get modem.default.user_name 2>/dev/null`
        password=`uci get modem.default.password 2>/dev/null`
        proto=`uci get modem.default.proto 2>/dev/null`
        mtu=`uci get modem.default.mtu 2>/dev/null`

        echo > $CONF
        echo "TZ_CONFIG_APN_NAME=$apn" >> $CONF
        echo "TZ_PPP_AUTH_TYPE=$auth_type" >> $CONF
        echo "TZ_PPP_USERNAME=$user_name" >> $CONF
        echo "TZ_PPP_PASSWORD=$password" >> $CONF
        echo "TZ_IP_STACK_MODE=$proto" >> $CONF
        echo "TZ_MTU_USB0=$mtu" >> $CONF
}

start_service()
{
        make_config
        sleep 5
        procd_open_instance
        procd_set_param command $PROG -s $CONF
        procd_set_param respawn
        procd_close_instance
}
